const cars = {
	state: {
		carsList: [],
		dataList: [{
				"_id": "660395ae213929f866ea7696",
				"create_date": 1711510958473,
				"name": "白酒",
				"children": [{
						"_id": "660396836e5d2ddb5179d474",
						"thumb": [{
							"url": "https://mp-35416368-0b79-4473-8aaf-8299d92e5687.cdn.bspapp.com/cloudstorage/27d21220-13cd-49bd-942a-dd5d80e11479.jpg",
							"name": "微信图片_20240327114339.jpg",
							"extname": "jpg",
							"path": "https://mp-35416368-0b79-4473-8aaf-8299d92e5687.cdn.bspapp.com/cloudstorage/27d21220-13cd-49bd-942a-dd5d80e11479.jpg"
						}],
						"name": "金六福",
						"category_id": "660395ae213929f866ea7696",
						"price": 238,
						"before_price": 238,
						"description": "",
						"sku_select": [],
						"numvalue": 0
					},
					{
						"_id": "660396d199c6244dcf5fa528",
						"thumb": [{
							"url": "https://mp-35416368-0b79-4473-8aaf-8299d92e5687.cdn.bspapp.com/cloudstorage/1809b695-9b6a-45ce-9b2c-92ac050d1f1f.jpg",
							"name": "微信图片_20240327114416.jpg",
							"extname": "jpg",
							"path": "https://mp-35416368-0b79-4473-8aaf-8299d92e5687.cdn.bspapp.com/cloudstorage/1809b695-9b6a-45ce-9b2c-92ac050d1f1f.jpg"
						}],
						"name": "贵州茅台",
						"category_id": "660395ae213929f866ea7696",
						"price": 198,
						"before_price": null,
						"description": "198起",
						"sku_select": [],
						"numvalue": 0
					},
					{
						"_id": "66039720a7c432936bc1e901",
						"thumb": [{
							"url": "https://mp-35416368-0b79-4473-8aaf-8299d92e5687.cdn.bspapp.com/cloudstorage/518177b7-5cf8-4f4c-84f2-3827e6e09dd9.jpg",
							"name": "微信图片_20240327114427.jpg",
							"extname": "jpg",
							"path": "https://mp-35416368-0b79-4473-8aaf-8299d92e5687.cdn.bspapp.com/cloudstorage/518177b7-5cf8-4f4c-84f2-3827e6e09dd9.jpg"
						}],
						"name": "中华老字号",
						"category_id": "660395ae213929f866ea7696",
						"price": 90,
						"before_price": null,
						"description": "",
						"sku_select": [],
						"numvalue": 0
					},
					{
						"_id": "6603ce3ba09a9b12d7b6e23a",
						"thumb": [{
							"url": "https://mp-35416368-0b79-4473-8aaf-8299d92e5687.cdn.bspapp.com/cloudstorage/f4725911-ed0c-44ed-ba17-8af0746e49b9.jpg",
							"name": "微信图片_20240327154156.jpg",
							"extname": "jpg",
							"path": "https://mp-35416368-0b79-4473-8aaf-8299d92e5687.cdn.bspapp.com/cloudstorage/f4725911-ed0c-44ed-ba17-8af0746e49b9.jpg"
						}],
						"name": "江小白大瓶",
						"category_id": "660395ae213929f866ea7696",
						"price": 78,
						"before_price": null,
						"description": "",
						"sku_select": [],
						"numvalue": 0
					}
				]
			},
			{
				"_id": "660395b6e0ec199b18a763e1",
				"create_date": 1711510966676,
				"name": "红酒",
				"children": [{
						"_id": "66039771bd022087df49d9ec",
						"thumb": [{
							"url": "https://mp-35416368-0b79-4473-8aaf-8299d92e5687.cdn.bspapp.com/cloudstorage/82e80aa5-a5ec-4aa3-8eb6-33e6cfbba78a.jpg",
							"name": "微信图片_20240327114436.jpg",
							"extname": "jpg",
							"path": "https://mp-35416368-0b79-4473-8aaf-8299d92e5687.cdn.bspapp.com/cloudstorage/82e80aa5-a5ec-4aa3-8eb6-33e6cfbba78a.jpg"
						}],
						"name": "古苏里拉-520干红葡萄",
						"category_id": "660395b6e0ec199b18a763e1",
						"price": 127,
						"before_price": null,
						"description": "",
						"sku_select": [],
						"numvalue": 0
					},
					{
						"_id": "6603978fa09a9b12d7a8834f",
						"thumb": [{
							"url": "https://mp-35416368-0b79-4473-8aaf-8299d92e5687.cdn.bspapp.com/cloudstorage/8def6be2-0e59-4534-b214-2e5f2c85db90.jpg",
							"name": "微信图片_20240327114444.jpg",
							"extname": "jpg",
							"path": "https://mp-35416368-0b79-4473-8aaf-8299d92e5687.cdn.bspapp.com/cloudstorage/8def6be2-0e59-4534-b214-2e5f2c85db90.jpg"
						}],
						"name": "古苏里拉-1314干葡萄酒",
						"category_id": "660395b6e0ec199b18a763e1",
						"price": 120,
						"before_price": null,
						"description": "",
						"sku_select": [],
						"numvalue": 0
					}
				]
			},
			{
				"_id": "660395c0fe975f74407ac584",
				"create_date": 1711510976100,
				"name": "啤酒类",
				"children": [{
						"_id": "660397bce0ec199b18a7efe4",
						"thumb": [{
							"url": "https://mp-35416368-0b79-4473-8aaf-8299d92e5687.cdn.bspapp.com/cloudstorage/71dd8143-78b7-4ad6-a258-7b0af9d66759.jpg",
							"name": "微信图片_20240327114458.jpg",
							"extname": "jpg",
							"path": "https://mp-35416368-0b79-4473-8aaf-8299d92e5687.cdn.bspapp.com/cloudstorage/71dd8143-78b7-4ad6-a258-7b0af9d66759.jpg"
						}],
						"name": "雪花精品",
						"category_id": "660395c0fe975f74407ac584",
						"price": 50,
						"before_price": null,
						"description": "",
						"sku_select": [],
						"numvalue": 0
					},
					{
						"_id": "660398189755e32830755d78",
						"thumb": [{
							"url": "https://mp-35416368-0b79-4473-8aaf-8299d92e5687.cdn.bspapp.com/cloudstorage/349e7a9e-fa1f-4999-81c9-f2129b991499.jpg",
							"name": "微信图片_20240327114502.jpg",
							"extname": "jpg",
							"path": "https://mp-35416368-0b79-4473-8aaf-8299d92e5687.cdn.bspapp.com/cloudstorage/349e7a9e-fa1f-4999-81c9-f2129b991499.jpg"
						}],
						"name": "教士",
						"category_id": "660395c0fe975f74407ac584",
						"price": 99,
						"before_price": null,
						"description": "",
						"sku_select": [{
							"skuName": "冰",
							"checked": true,
							"children": [{
									"name": "不冰",
									"checked": true
								},
								{
									"name": "冰",
									"checked": true
								}
							],
							"_id": "660398026e5d2ddb517a3f7e"
						}],
						"numvalue": 0
					},
					{
						"_id": "6603984c7ad52dfccc1d7921",
						"thumb": [{
							"url": "https://mp-35416368-0b79-4473-8aaf-8299d92e5687.cdn.bspapp.com/cloudstorage/ac9fe22f-2875-4854-b19f-0e280af7ed55.jpg",
							"name": "微信图片_20240327114508.jpg",
							"extname": "jpg",
							"path": "https://mp-35416368-0b79-4473-8aaf-8299d92e5687.cdn.bspapp.com/cloudstorage/ac9fe22f-2875-4854-b19f-0e280af7ed55.jpg"
						}],
						"name": "科罗娜",
						"category_id": "660395c0fe975f74407ac584",
						"price": 178,
						"before_price": null,
						"description": "",
						"sku_select": [{
							"_id": "660398026e5d2ddb517a3f7e",
							"skuName": "冰",
							"checked": true,
							"children": [{
									"name": "不冰",
									"checked": true
								},
								{
									"name": "冰",
									"checked": true
								}
							]
						}],
						"numvalue": 0
					},
					{
						"_id": "6603d3dc7ad52dfccc2d2e79",
						"thumb": [{
							"url": "https://mp-35416368-0b79-4473-8aaf-8299d92e5687.cdn.bspapp.com/cloudstorage/a01b639d-b21b-4aa6-aa96-a8c35908d2f9.jpg",
							"name": "微信图片_20240327114454.jpg",
							"extname": "jpg",
							"path": "https://mp-35416368-0b79-4473-8aaf-8299d92e5687.cdn.bspapp.com/cloudstorage/a01b639d-b21b-4aa6-aa96-a8c35908d2f9.jpg"
						}],
						"name": "燕京鲜啤",
						"category_id": "660395c0fe975f74407ac584",
						"price": 55,
						"before_price": null,
						"description": "",
						"sku_select": [{
								"_id": "660398026e5d2ddb517a3f7e",
								"skuName": "冰",
								"checked": true,
								"children": [{
										"name": "不冰",
										"checked": true
									},
									{
										"name": "冰",
										"checked": true
									}
								]
							},
							{
								"skuName": "一件24听",
								"checked": true,
								"children": [{
									"name": "一件24听",
									"checked": true
								}],
								"_id": "6603d3ce8620667bb41cb36d"
							}
						],
						"numvalue": 0
					}
				]
			}
		]


	},
	mutations: {
		setCarsList(state, params) {


			let {
				item,
				num
			} = params;

			let caritem = {
				_id: item._id || item.goodsid,
				numvalue: num,
				name: item.name,
				price: item.price,
				before_price: item.before_price,
				thumb: item.thumb
			}
			let idx = state.carsList.findIndex(car => {
				return car._id == caritem._id
			})

			if (idx < 0) {
				state.carsList.push(caritem)
			} else {
				state.carsList[idx].numvalue = caritem.numvalue;
				if (state.carsList[idx].numvalue <= 0) state.carsList.splice(idx, 1);
			}
			let current = findItemById(state.dataList, item._id)
			if (current) {
				current.numvalue = num
			}
		},
		clearCarsList(state) {
			state.carsList = []
			state.dataList.map(items => {
				items.children.map(v => {
					v.numvalue = 0
				})
			})
		},
		setDataList(state, data) {
			state.dataList = data
		}
	}
}

// 递归函数用于查找匹配的ID
function findItemById(array, _id) {
	for (let i = 0; i < array.length; i++) {
		const item = array[i];
		if (item._id === _id) {
			return item;
		}
		if (item.children && item.children.length > 0) {
			const found = findItemById(item.children, _id);
			if (found) {
				return found;
			}
		}
	}
	return null;
}

export default cars